import {
	orderConfirm,
	orderSubmit,
} from "@/api/payment/index.js"


module.exports = {

	data() {
		return {
			timer: null,
			orderNo: null, //订单号
		}
	},
	onLoad() {

	},

	methods: {
		orderConfirm(option) {
			let {
				params,
				success,
				fail,
				complete,
			} = option

			orderConfirm(params).then(result => {
				orderSubmit(params).then(res => {
					console.log(res, "res")
					if (res.data) {
						this.orderNo = res.data
						success&&success(res.data)
					}else{
						fail&&fail("orderSubmit:fail")
						complete && complete()
					}
				}).catch(e=>{
					fail&&fail("orderSubmit:fail")
					complete && complete()
				})
			}).catch(e=>{
				fail&&fail("orderSubmit:fail")
				complete && complete()
			})
		}
	},
	onUnload() {
		clearTimeout(this.timer)
	},

}
